const gulp = require('gulp');
const cleanCSS = require('gulp-clean-css');
const babel=require('gulp-babel');
const uglify=require('gulp-uglify');
const htmlmin=require('gulp-htmlmin');
const connect=require('gulp-connect');
const sass=require('gulp-sass');

gulp.task('css', () => {
   gulp.src('src/css/**/*.css')
    .pipe(cleanCSS())
    .pipe(gulp.dest('dist/css'));
});


gulp.task('js', () => {
   gulp.src('src/js/*.js')
    .pipe(babel({
    	presets:['env']
    }))
    .pipe(uglify())
    .pipe(gulp.dest('dist/js'))
});

gulp.task('html', () => {
   gulp.src('src/**/*.html')
    .pipe(htmlmin({collapseWhitespace:true,minifyJS:true,minifyCSS:true}))
    .pipe(gulp.dest('dist'));
});

gulp.task('img', () => {
   gulp.src('src/img/**/*.*')
    .pipe(gulp.dest('dist/img'));
});

gulp.task('copy',['img']);

gulp.task('server',()=>{
	connect.server({
		root:'dist',
		port:3000, 
		livereload:true
	})
});

gulp.task('sass',()=>{
  gulp.src('src/scss/**/*.scss')
  .pipe(sass())
  .pipe(gulp.dest('dist/css'))
})
gulp.task('watch',()=>{
  gulp.watch('src/scss/**/*.scss',['sass'])
})

gulp.task('default',['css','js','html','copy','server','sass'])


